﻿using System;

using System.Collections.Generic;
using System.Text;

using Acid.OpenGLES;
using Acid.Math;

namespace Acid.Graphics
{
    public unsafe class Transform
    {
        private Matrix world;
        private Matrix view;
        private Matrix projection;

        public Transform()
        {
            this.world      = Matrix.Identity;
            this.view       = Matrix.Identity;
            this.projection = Matrix.Identity;
        }

        public Matrix World
        {
            get
            {
                return this.world;
            }
            set
            {
                this.world = value;

                Matrix mv = this.world * this.view;

                float[] mva = mv.ToArray();

                fixed (float* mvp = &mva[0])
                {
                    gl.MatrixMode(gl.GL_MODELVIEW);

                    gl.LoadIdentity();

                    gl.MultMatrixf(mvp);
                }
            }
        }
        public Matrix View
        {
            get
            {
                return this.view;
            }
            set
            {
                this.view = value;

                Matrix mv = this.world * this.view;

                float[] mva = mv.ToArray();

                fixed (float* mvp = &mva[0])
                {
                    gl.MatrixMode(gl.GL_MODELVIEW);

                    gl.LoadIdentity();

                    gl.MultMatrixf(mvp);
                }
            }
        }
        public Matrix Projection
        {
            get
            {
                return this.projection;
            }
            set
            {
                this.projection = value;

                float[] pa = this.projection.ToArray();

                fixed (float* pp = &pa[0])
                {
                    gl.MatrixMode(gl.GL_PROJECTION);

                    gl.LoadIdentity();

                    gl.MultMatrixf(pp);
                }

                
            }
        }

    }
}
